<template>
  <div class="video-view">
    <div class="container">
      <h1 class="page-title">视频制作</h1>
      
      <div class="video-tools">
        <div class="tool-section">
          <h2>AI视频生成</h2>
          <div class="video-generator">
            <div class="input-group">
              <label>视频描述</label>
              <textarea 
                v-model="videoDescription" 
                placeholder="描述您想要生成的视频内容..."
                rows="4"
              ></textarea>
            </div>
            
            <div class="input-group">
              <label>视频风格</label>
              <select v-model="selectedStyle">
                <option value="">选择风格</option>
                <option value="realistic">写实风格</option>
                <option value="cartoon">卡通风格</option>
                <option value="artistic">艺术风格</option>
                <option value="cinematic">电影风格</option>
              </select>
            </div>
            
            <div class="input-group">
              <label>视频时长</label>
              <div class="duration-slider">
                <input 
                  type="range" 
                  v-model="videoDuration" 
                  min="5" 
                  max="60" 
                  step="5"
                />
                <span>{{ videoDuration }}秒</span>
              </div>
            </div>
            
            <button 
              @click="generateVideo" 
              :disabled="!videoDescription.trim() || isGenerating"
              class="generate-btn"
            >
              <i v-if="isGenerating" class="fas fa-spinner fa-spin"></i>
              <span v-else>生成视频</span>
            </button>
          </div>
        </div>

        <div class="tool-section">
          <h2>视频编辑工具</h2>
          <div class="edit-tools">
            <div class="tool-card" v-for="tool in editTools" :key="tool.name">
              <div class="tool-icon">
                <i :class="tool.icon"></i>
              </div>
              <h3>{{ tool.name }}</h3>
              <p>{{ tool.description }}</p>
              <button @click="openTool(tool.name)" class="tool-btn">
                使用工具
              </button>
            </div>
          </div>
        </div>
      </div>

      <div class="video-gallery" v-if="generatedVideos.length > 0">
        <h2>生成的视频</h2>
        <div class="video-grid">
          <div 
            v-for="(video, index) in generatedVideos" 
            :key="index"
            class="video-item"
          >
            <div class="video-preview">
              <div class="video-placeholder">
                <i class="fas fa-play"></i>
                <span>视频预览</span>
              </div>
            </div>
            <div class="video-info">
              <h3>{{ video.title }}</h3>
              <p>{{ video.description }}</p>
              <div class="video-actions">
                <button @click="downloadVideo(index)" class="action-btn">
                  <i class="fas fa-download"></i>
                  下载
                </button>
                <button @click="editVideo(index)" class="action-btn">
                  <i class="fas fa-edit"></i>
                  编辑
                </button>
                <button @click="shareVideo(index)" class="action-btn">
                  <i class="fas fa-share"></i>
                  分享
                </button>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="templates-section">
        <h2>视频模板</h2>
        <div class="template-grid">
          <div 
            v-for="template in videoTemplates" 
            :key="template.id"
            class="template-card"
            @click="useTemplate(template)"
          >
            <div class="template-preview">
              <img :src="template.preview" :alt="template.name" />
              <div class="template-overlay">
                <i class="fas fa-play"></i>
              </div>
            </div>
            <div class="template-info">
              <h3>{{ template.name }}</h3>
              <p>{{ template.description }}</p>
              <div class="template-tags">
                <span v-for="tag in template.tags" :key="tag" class="tag">
                  {{ tag }}
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

interface GeneratedVideo {
  title: string
  description: string
  url: string
  createdAt: Date
}

interface VideoTemplate {
  id: string
  name: string
  description: string
  preview: string
  tags: string[]
}

const videoDescription = ref('')
const selectedStyle = ref('')
const videoDuration = ref(15)
const isGenerating = ref(false)

const generatedVideos = ref<GeneratedVideo[]>([])

const editTools = ref([
  {
    name: '智能剪辑',
    description: 'AI自动识别精彩片段并生成剪辑',
    icon: 'fas fa-cut'
  },
  {
    name: '背景音乐',
    description: '为视频添加合适的背景音乐',
    icon: 'fas fa-music'
  },
  {
    name: '字幕生成',
    description: '自动生成并同步字幕',
    icon: 'fas fa-closed-captioning'
  },
  {
    name: '特效滤镜',
    description: '应用各种视觉效果和滤镜',
    icon: 'fas fa-magic'
  },
  {
    name: '转场效果',
    description: '添加专业的转场动画',
    icon: 'fas fa-film'
  },
  {
    name: '色彩校正',
    description: '智能调整视频色彩和亮度',
    icon: 'fas fa-palette'
  }
])

const videoTemplates = ref<VideoTemplate[]>([
  {
    id: '1',
    name: '产品展示',
    description: '专业的产品展示视频模板',
    preview: '/api/templates/product-preview.jpg',
    tags: ['商业', '产品', '专业']
  },
  {
    id: '2',
    name: '旅行vlog',
    description: '记录美好旅行时光的模板',
    preview: '/api/templates/travel-vlog.jpg',
    tags: ['旅行', '生活', 'vlog']
  },
  {
    id: '3',
    name: '教育课程',
    description: '适合在线教育的视频模板',
    preview: '/api/templates/education.jpg',
    tags: ['教育', '课程', '学习']
  },
  {
    id: '4',
    name: '活动宣传',
    description: '活动宣传和推广视频模板',
    preview: '/api/templates/event-promo.jpg',
    tags: ['活动', '宣传', '推广']
  }
])

const generateVideo = async () => {
  if (!videoDescription.value.trim()) return
  
  isGenerating.value = true
  
  // 模拟视频生成过程
  setTimeout(() => {
    const newVideo: GeneratedVideo = {
      title: `AI生成视频 ${generatedVideos.value.length + 1}`,
      description: videoDescription.value,
      url: `/api/videos/generated-${Date.now()}.mp4`,
      createdAt: new Date()
    }
    
    generatedVideos.value.unshift(newVideo)
    isGenerating.value = false
    videoDescription.value = ''
    
    // 显示成功消息
    alert('视频生成成功！')
  }, 3000)
}

const openTool = (toolName: string) => {
  alert(`打开${toolName}工具`)
}

const downloadVideo = (index: number) => {
  const video = generatedVideos.value[index]
  alert(`下载视频: ${video.title}`)
}

const editVideo = (index: number) => {
  const video = generatedVideos.value[index]
  alert(`编辑视频: ${video.title}`)
}

const shareVideo = (index: number) => {
  const video = generatedVideos.value[index]
  alert(`分享视频: ${video.title}`)
}

const useTemplate = (template: VideoTemplate) => {
  alert(`使用模板: ${template.name}`)
}
</script>

<style scoped>
.video-view {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 2rem 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.page-title {
  text-align: center;
  color: white;
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 3rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.video-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3rem;
  margin-bottom: 4rem;
}

.tool-section {
  background: white;
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.tool-section h2 {
  color: #333;
  font-size: 1.5rem;
  margin-bottom: 2rem;
  text-align: center;
}

.input-group {
  margin-bottom: 1.5rem;
}

.input-group label {
  display: block;
  color: #333;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.input-group textarea,
.input-group select {
  width: 100%;
  padding: 1rem;
  border: 2px solid #e9ecef;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.3s ease;
}

.input-group textarea:focus,
.input-group select:focus {
  border-color: #667eea;
}

.duration-slider {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.duration-slider input[type="range"] {
  flex: 1;
}

.duration-slider span {
  color: #667eea;
  font-weight: 500;
  min-width: 60px;
}

.generate-btn {
  width: 100%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  padding: 1rem;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.generate-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}

.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.edit-tools {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.tool-card {
  text-align: center;
  padding: 1.5rem;
  border: 2px solid #e9ecef;
  border-radius: 12px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.tool-card:hover {
  border-color: #667eea;
  transform: translateY(-2px);
}

.tool-icon {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
}

.tool-icon i {
  font-size: 1.5rem;
  color: white;
}

.tool-card h3 {
  color: #333;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.tool-card p {
  color: #666;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.tool-btn {
  background: #f8f9fa;
  color: #667eea;
  border: 1px solid #667eea;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tool-btn:hover {
  background: #667eea;
  color: white;
}

.video-gallery,
.templates-section {
  background: white;
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  margin-bottom: 3rem;
}

.video-gallery h2,
.templates-section h2 {
  color: #333;
  font-size: 1.5rem;
  margin-bottom: 2rem;
  text-align: center;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
}

.video-item {
  border: 1px solid #e9ecef;
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.video-item:hover {
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.video-preview {
  height: 200px;
  background: #f8f9fa;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-placeholder {
  text-align: center;
  color: #6c757d;
}

.video-placeholder i {
  font-size: 3rem;
  margin-bottom: 1rem;
  display: block;
}

.video-info {
  padding: 1.5rem;
}

.video-info h3 {
  color: #333;
  margin-bottom: 0.5rem;
}

.video-info p {
  color: #666;
  margin-bottom: 1rem;
}

.video-actions {
  display: flex;
  gap: 0.5rem;
}

.action-btn {
  flex: 1;
  background: #f8f9fa;
  color: #667eea;
  border: 1px solid #667eea;
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-btn:hover {
  background: #667eea;
  color: white;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 2rem;
}

.template-card {
  border: 1px solid #e9ecef;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
}

.template-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
}

.template-preview {
  height: 150px;
  background: #f8f9fa;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.template-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.template-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.template-card:hover .template-overlay {
  opacity: 1;
}

.template-overlay i {
  color: white;
  font-size: 2rem;
}

.template-info {
  padding: 1.5rem;
}

.template-info h3 {
  color: #333;
  margin-bottom: 0.5rem;
}

.template-info p {
  color: #666;
  margin-bottom: 1rem;
}

.template-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  background: #f0f4ff;
  color: #667eea;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
}

@media (max-width: 768px) {
  .video-tools {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
  
  .page-title {
    font-size: 2rem;
  }
  
  .edit-tools {
    grid-template-columns: 1fr;
  }
  
  .video-grid,
  .template-grid {
    grid-template-columns: 1fr;
  }
}
</style> 